using System;
using System.Collections.ObjectModel;
using System.Windows.Input;
using iopt.solvency.pillarone.client.desktop.Helpers;
//using iopt.solvency.pillarone.client.desktop.Models;

namespace iopt.solvency.pillarone.client.desktop.ViewModels
{
    public class MainWindowViewModel : BaseViewModel
    {
        #region Properties
        private string _Title = "Outil  de calcul du pillier 1";
        private VMEntityDesigner VMEntityDesigner;
        private VMParameterDesigner VMParameterDesigner;
        public string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                _Title = value;
                OnPropertyChanged("Title");
            }
        }
        public ObservableCollection<VMDocument> Documents { get; private set; }

        public ObservableCollection<VMTool> Tools { get; private set; }

        #endregion

        #region Commands
        public DelegateCommand SaveChangeCommand
        {
            get { return new DelegateCommand(SaveChangeExecute); }
        }
        private void SaveChangeExecute(object parameter)
        {
            //var vmmainwindow = App.Current.MainWindow.DataContext as iopt.solvency.pillarone.client.desktop.ViewModels.MainWindowViewModel;

            //vmmainwindow.Tools.Remove(this);

            //vmmainwindow.Tools.Add(this);
        }
        public DelegateCommand SaveAllChangeCommand
        {
            get { return new DelegateCommand(SaveAllChangeExecute); }
        }
        private void SaveAllChangeExecute(object parameter)
        {
            //var vmmainwindow = App.Current.MainWindow.DataContext as iopt.solvency.pillarone.client.desktop.ViewModels.MainWindowViewModel;

            //vmmainwindow.Tools.Remove(this);

            //vmmainwindow.Tools.Add(this);

            var generator = new Helpers.ModelGenerator();
            generator.ModelDefinition = this.VMEntityDesigner.Model;
            generator.Parameters = this.VMParameterDesigner.Params;
            System.IO.File.WriteAllText(this.VMEntityDesigner.Model.FilePath, generator.TransformText());
            Views.ActionDesigner.completion.ProcessInput(generator.TransformText(), this.VMEntityDesigner.Model.FilePath);
        }
 
        #endregion

        #region Ctor
        public MainWindowViewModel()  
        {
            this.Documents = new ObservableCollection<VMDocument>();
            this.Tools = new ObservableCollection<VMTool>();

            this.Tools.Add(new VMProjectExplorer());
            this.Tools.Add(new VMModelExplorer());

            this.VMEntityDesigner = new VMEntityDesigner();
            this.Tools.Add(this.VMEntityDesigner);

            this.VMParameterDesigner = new VMParameterDesigner();
            this.Tools.Add(this.VMParameterDesigner);
            this.Tools.Add(new VMWorkflowDesigner());
        }
        #endregion
      
    }
}